Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Card): updated markup for actionable cards #738

Merged
merged 4 commits into from
Aug 26, 2024

Conversation

thatblindgeye
Copy link
Collaborator

Closes #736

A todo is to update the message logic so that it'll only spit out the prop reference that is actually present (vs now it just spits out both name and selectableActionId props even if only one is present).

Also attempted a helper that could possibly be used in relation to #695

@@ -0,0 +1,9 @@
import { JSXElement } from "estree-jsx";

export function nodeIsComponentNamed(node: JSXElement, componentName: string) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamviktora seems like you and I built similar helpers (this from you, checkMatchingJSXOpeningElement in the nodeMatches file from me)? Wdyt about us combining them into a single rule + if so, any preference on naming?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep yours checkMatchingJSXOpeningElement, it is more general and we already have it as part of the initial general rule. I can refactor the two rules that are using this nodeIsComponentNamed to use checkMatchingJSXOpeningElement and then delete this helper.

Copy link
Contributor

@adamviktora adamviktora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! I really like the new helpers 🔥

Some comments bellow regarding dealing with ImportDefaultSpecifier and few more

},
// Passed as a variable reference
{
code: `import { Card, CardHeader } from '@patternfly/react-core'; const obj = {name: 'Test', selectableActionId: 'Id'}; <Card isClickable><CardHeader selectableActions={obj} /></Card>`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have more of a philosophical question to this - whether it is OK to remove / modify consumers variables. Because they might be using these variables for other stuff too. They shouldn't use them for multiple purposes, and they probably aren't, but it is technically possible, so we might break some code by modifying them.

I know we also have other issues opened, where the goal is to modify stuff in the place of variable declaration - I agree it is more convenient for the consumers too after all. I am just afraid we might break something - but if we do, it probably means it was a badly written code, ... so I am ok with modifying the variables.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a good point. In this particular case the variable may not be shared with anything other than a CardHeader component since it's such a specific object (though wouldn't be surprised). But for something like a prop that accepts a color, maybe that's a valid case where a variable is being used in other places (maybe something like a "color" variable that possibly shouldn't be updated if it's being used in other places).

If anything we can base it on a case-by-case basis, but worth keeping in mind when trying to apply a fix to a variable like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @wise-king-sullyman in case you had any thoughts

const isIdentifier = property.key.type === "Identifier";
const { computed } = property;

// E.g. const key = "key"; {[key]: value}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for these examples in comments

Comment on lines 17 to 45
if (
attribute.value.type === "JSXExpressionContainer" &&
attribute.value.expression.type === "Identifier"
) {
const scope = context.getSourceCode().getScope(attribute);
const variableDeclaration = getVariableDeclaration(
attribute.value.expression.name,
scope
);

return variableDeclaration && variableDeclaration.defs[0].node.init;
}

if (attribute.value.type === "Literal") {
return attribute.value;
}
if (
attribute.value.type === "JSXExpressionContainer" &&
["ObjectExpression", "MemberExpression"].includes(
attribute.value.expression.type
)
) {
return attribute.value.expression;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, but since two of these three outcomes require the value type to be JSXExpressionContainer it could be refactored to simplify the logic a bit. Additionally refactoring to use a switch and deconstructing the expression out would also tidy things up a but.

Not a blocker though.

{
message:
"The markup for clickable-only cards has been updated.Additionally, the `selectableActions.selectableActionId` and `selectableActions.name` props are no longer necessary to pass to CardHeader for clickable-only cards.",
// message: `The markup for clickable-only cards has been updated, now using button and anchor elements for the respective clickable action. The \`selectableActions.selectableActionId\` and \`selectableActions.name\` props are also no longer necessary for clickable-only cards. Passing them in will not cause any errors, but running the fix for this rule will remove them.`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intend to leave this in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops

Copy link
Contributor

@adamviktora adamviktora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@adamviktora adamviktora merged commit 8941915 into patternfly:main Aug 26, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Card - update markup/API has changed
3 participants